package com.hontech.bv.ui.fragment.ice

import android.view.View
import android.widget.Button
import com.hontech.bv.R
import com.hontech.bv.conn.api.Arm
import com.hontech.bv.conn.api.Ice
import com.hontech.bv.task.onClick
import com.hontech.bv.ui.window.FormDialog
import com.hontech.bv.ui.window.FormKV
import com.hontech.bv.ui.wrapDialog

private fun showDropIceDialog() {
    FormDialog("出冰", "确定", arrayOf(
        FormKV("出冰时间", "3")
    )){
        val sec = it[0]
        wrapDialog("出冰", "出冰时间:${sec}秒") {
            Ice.dropIce(sec)
        }
    }.show()
}

class CtrlDelegate (view: View) {

    private val btnAutoDraw = view.findViewById<Button>(R.id.id_ice_btn_draw_auto)
    private val btnStopDraw = view.findViewById<Button>(R.id.id_ice_btn_draw_stop)

    private val btnAutoIce = view.findViewById<Button>(R.id.id_ice_btn_ice_auto)
    private val btnStopIce = view.findViewById<Button>(R.id.id_ice_btn_ice_stop)

    private val btnDropIce = view.findViewById<Button>(R.id.id_ice_btn_drop_ice)

    init {
        btnDropIce.setOnClickListener { showDropIceDialog() }

        btnAutoDraw.onClick {
            wrapDialog("抽水控制", "自动抽水") {
                Ice.drawCtrl(0)
            }
        }
        btnStopDraw.onClick {
            wrapDialog("抽水控制", "停止抽水") {
                Ice.drawCtrl(1)
            }
        }

        btnAutoIce.onClick {
            wrapDialog("制冰控制", "自动制冰") {
                Ice.makeCtrl(0)
            }
        }
        btnStopIce.onClick {
            wrapDialog("制冰控制", "停止制冰") {
                Ice.makeCtrl(1)
            }
        }
    }

}